﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LordJS.Models;
using LordJS.Filters;

namespace LordJS.Controllers
{
    public class AjaxController : Controller
    {
        [HttpPost]
        public JsonResult GetJsonResult(List<Person> persons)
        {
            var newPersons = new List<Person>();
            foreach (Person person in persons)
            {
                Person p = new Person
                {
                    Name = "Employee - " + person.Name,
                    Age = person.Age + 10
                };

                newPersons.Add(p);
            }
            
            return Json(newPersons);
        }

        [HttpPost, AjaxAction]
        public JsonResult AjaxPostTest()
        {
            Thread.Sleep(3000);

            return Json(new { msg = "The criteria is Invalid, please check and try again" });
        }
    }
}
